﻿using System.Globalization;
using Microsoft.Phone.Shell;
using Tfs.OnTheRoad.Model;
namespace Tfs.OnTheRoad.Commands
{
    /// <summary>
    /// Navigates to ProjectOverview Page
    /// </summary>
    public class NavigateToProjectCommand : BaseCommand
    {
        public override void Execute(object parameter)
        {
            System.Windows.Controls.SelectionChangedEventArgs args = parameter as System.Windows.Controls.SelectionChangedEventArgs;
            if(args!=null && args.AddedItems.Count>0)
            {            
                // Set the selected item as the current item.
                var currentProject = args.AddedItems[0] as Project;
                PhoneApplicationService.Current.State["CurrentProject"] = currentProject;
                // Navigate to the new page.
                NavigateTo(string.Format(CultureInfo.InvariantCulture, "/Pages/ProjectOverviewPage.xaml?projectName={0}", currentProject.Name));
            }     
        }
    }
}